require 'minitest/autorun'
require 'minitest/hooks/test'

require '../base/aio_init'

class TestAllDevices < MiniTest::Test
  include Minitest::Hooks

  def before_all
    @device_manager = AioInit.new.device_manager
    @each_devices = Proc.new do |&block| 
      @device_manager.each_devices_of('cisco', 'maipu', 'h3c') &block
    end
  end

  def test_show_version
    @device_manager.each_devices_of('cisco', 'maipu') do |k|
      refute_empty k.device_name
      refute_empty k.ios_version
      refute_empty k.soft_image
      refute_empty k.uptime
    end

    @device_manager.each_devices_of_h3c do |k|
      refute_empty k.device_name
      refute_empty k.ios_version
      refute_empty k.uptime

      # version中没有soft_image
      assert_nil k.soft_image
    end

  end

  def test_show_ip_interface
    @device_manager.each_devices_of('cisco', 'maipu', 'h3c') do |k|
      refute_empty k.get_manager_ip
    end
  end

  def test_show_clock
    @device_manager.each_devices_of('cisco', 'maipu', 'h3c') do |k|
      refute_empty k.clock
    end
  end

  # 板卡序列号信息
  # FIXME Maipu 暂时没有支持
  def test_show_inventory
    @device_manager.each_devices_of('cisco', 'h3c') do |k|
      inv = k.inventory
      assert inv.kind_of? Array
      assert inv.size > 1
      refute_empty inv[0][:name]
      refute_empty inv[0][:pid]
      refute_empty inv[0][:sn]
      refute_empty inv[0][:description]
    end
  end

  def test_show_process_cpu
    @device_manager.each_devices_of('cisco', 'maipu', 'h3c') do |k|
      refute_empty k.cpu_percent
    end
  end

  def test_show_process_memory
    @device_manager.each_devices_of('cisco', 'maipu', 'h3c') do |k|
      refute_empty k.memory_percent
    end
  end

end
